#!/bin/bash
# 克隆 Node.js 源码
if [ ! -d "third_party_node" ]; then
    git clone https://gitee.com/mirrors/nodejs.git nodejsv14 -b v14.21.1
fi

cd nodejsv14
chmod -R +x tools/
chmod +x configure
arch=$(arch)
# NODE_NAME="node-v14.21.1-linux-$arch"
NODE_NAME="node-v14.21.1-linux-x64"


# 配置构建
./configure --ninja --prefix=/workspace/local/$NODE_NAME
# 使用所有 CPU 核心构建
make -j$(nproc)
make install
make test-only

if [ -f "/workspace/local/$NODE_NAME/bin/node" ]; then
    echo "构建成功！"
    echo "创建压缩包..."
    cd /workspace/local
    tar -czf $NODE_NAME.tar.gz $NODE_NAME

    echo "✅ 打包完成: $NODE_NAME.tar.gz"
    echo "📦 文件大小: $(du -h $NODE_NAME.tar.gz | cut -f1)"


else
    echo "构建失败！"
    exit 1
fi